/**
 * Copyright &copy; 2012-2016 <a href="https://www.kaaction.com">KAA</a> All rights reserved All rights reserved.
 */
package com.kaaction.modules.mer.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaaction.common.persistence.Page;
import com.kaaction.common.service.CrudService;
import com.kaaction.modules.mer.entity.Sku;
import com.kaaction.modules.mer.dao.SkuDao;

/**
 * 商品种类Service
 * @author huanghaiming
 * @version 2017-05-21
 */
@Service
@Transactional(readOnly = true)
public class SkuService extends CrudService<SkuDao, Sku> {

	public Sku get(String id) {
		return super.get(id);
	}
	
	public List<Sku> findList(Sku sku) {
		return super.findList(sku);
	}
	
	public Page<Sku> findPage(Page<Sku> page, Sku sku) {
		return super.findPage(page, sku);
	}
	
	@Transactional(readOnly = false)
	public void save(Sku sku) {
		super.save(sku);
	}
	
	@Transactional(readOnly = false)
	public void delete(Sku sku) {
		super.delete(sku);
	}

	public Sku findSku(String spuId, String selectedColorId, String selectedSizeId) {
		return super.dao.findSku(spuId,selectedColorId,selectedSizeId);
	}

	@Transactional(readOnly = false)
	public Map<String, Object> deleteSku(String id) {
		Map<String,Object> map = new HashMap<String,Object>();
		int cnt = super.dao.deleteSku(id);
		if(cnt>0){
			map.put("code", "0");
			map.put("msg", "删除成功");
		}else{
			map.put("code", "1");
			map.put("msg", "删除失败，请联系管理员");
		}
		return map;
	}

	public Sku findSkuBySpuId(String spuId) {
		return super.dao.findSkuBySpuId(spuId);
	}
	
}